﻿<Window x:Class="ManoMachine.IDE.Shell"
		xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
		xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
		xmlns:Views="clr-namespace:ManoMachine.IDE.Views" Title="MainWindow" Height="550" Width="725"
		DataContext="{Binding RelativeSource={RelativeSource Mode=Self}, Path=ViewModel}" Name="LocalThis"
		xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" xmlns:Convertrs="clr-namespace:ManoMachine.IDE.Convertrs" WindowState="Maximized">
	<Window.Resources>
		<Convertrs:BoleanInventionConverter x:Key="_boleanInventionConverter"/>
		<Convertrs:CpuContentToString x:Key="_cpuContentToString"/>
	</Window.Resources>
	<Grid Name="Layouroot">
		<Grid.RowDefinitions>
			<RowDefinition Height="Auto" />
			<RowDefinition Height="*" />
			<RowDefinition Height="Auto" />
		</Grid.RowDefinitions>

		<DockPanel LastChildFill="False">
			<DockPanel.Background>

				<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
					<GradientStop Color="#FF7EC8E9" Offset="0.113"/>
					<GradientStop Color="#FFD0E9F3" Offset="1"/>
					<GradientStop Color="#FFA8E0EF"/>
					<GradientStop Color="#B3059DA9" Offset="0.204"/>
				</LinearGradientBrush>

			</DockPanel.Background>
			<WrapPanel DockPanel.Dock="Left" VerticalAlignment="Center">
				<WrapPanel.Resources>
					<Style TargetType="telerik:RadButton">
						<Setter Property="Margin" Value="10,5"/>
						<Setter Property="Width" Value="80"/>
						<Setter Property="Height" Value="32"/>

					</Style>
					<Style TargetType="telerik:RadComboBox">
						<Setter Property="Margin" Value="10,5"/>
						<Setter Property="MinWidth" Value="130"/>
						<Setter Property="Height" Value="25"/>

					</Style>
				</WrapPanel.Resources>

				<telerik:RadButton  Click="CompilerClicked" IsEnabled="{Binding ElementName=LocalThis, Path=ViewModel.IsInEmulationMode, Converter={StaticResource _boleanInventionConverter},ConverterParameter=i}" >
					<StackPanel VerticalAlignment="Center" Orientation="Horizontal" Margin="2,2,5,2">
						<Image Source="../Resources/Compile.png" Height="25" Width="25" Stretch="Fill" />
						<TextBlock VerticalAlignment="Center" Text="Compile"/>
					</StackPanel>
				</telerik:RadButton>
				<telerik:RadButton  Click="EmulateClicked" IsEnabled="{Binding ElementName=LocalThis, Path=ViewModel.IsInEmulationMode, Converter={StaticResource _boleanInventionConverter},ConverterParameter=i}">
					<StackPanel VerticalAlignment="Center" Orientation="Horizontal" Margin="2,2,5,2">
						<Image Source="../Resources/Run.png" Height="25" Width="25" Stretch="Fill" />
						<TextBlock VerticalAlignment="Center" Text="Emulate"/>
					</StackPanel>
				</telerik:RadButton>

				<CheckBox Content="Is parallel" IsThreeState="False" IsChecked="{Binding ElementName=LocalThis, Path=ViewModel.IsParallel}" VerticalAlignment="Center" Margin="10,5"/>

				<Border Height="23" Background="Black" BorderBrush="Black" BorderThickness="1" Margin="20,0,20,0"/>

				<telerik:RadButton Click="NextStepClicked" IsEnabled="{Binding ElementName=LocalThis, Path=ViewModel.IsInEmulationMode, Converter={StaticResource _boleanInventionConverter}}">
					<StackPanel VerticalAlignment="Center" Orientation="Horizontal" Margin="2,2,5,2">
						<Image Source="../Resources/next.png" Height="20" Width="20" Stretch="Fill" />
						<TextBlock VerticalAlignment="Center" Text="Step forward"/>
					</StackPanel>
				</telerik:RadButton>
				<telerik:RadButton Content="Run to end" Click="RunToEndClick" IsEnabled="{Binding ElementName=LocalThis, Path=ViewModel.IsInEmulationMode, Converter={StaticResource _boleanInventionConverter}}"/>

				<Border Height="23" Background="Black" BorderBrush="Black" BorderThickness="1" Margin="20,0,20,0"/>

				<TextBlock VerticalAlignment="Center" Text="Examples: " Margin="10,5,1,5"/>

				<telerik:RadComboBox SelectedIndex="0" IsEditable="True" IsReadOnly="True" SelectionChanged="ExamplesSelectionChanged"
									 IsEnabled="{Binding ElementName=LocalThis, Path=ViewModel.IsInEmulationMode, Converter={StaticResource _boleanInventionConverter},ConverterParameter=i}">
					<telerik:RadComboBoxItem Content="Load Example 1"/>
					<telerik:RadComboBoxItem Content="Load Example 2"/>
					<telerik:RadComboBoxItem Content="Load Example 3"/>
					<telerik:RadComboBoxItem Content="Load Example 4"/>
				</telerik:RadComboBox>

				<!--    <Border Height="23" Background="Black" BorderBrush="Black" BorderThickness="1" Margin="20,0,20,0"/>-->

				<CheckBox Content="Syntax Highlighting" IsThreeState="False" Margin="10,5,1,5" IsChecked="True" Name="syntaxCheck" VerticalAlignment="Center"/>

			</WrapPanel>

			<!---->
				 <ListBox SelectedIndex="0" DockPanel.Dock="Right" BorderThickness="0" VerticalAlignment="Center" SelectionChanged="ListBox_SelectionChanged" Background="Transparent"  >
					<ListBox.ItemsPanel>
						<ItemsPanelTemplate>
							<WrapPanel Orientation="Horizontal"/>
						</ItemsPanelTemplate>
					</ListBox.ItemsPanel>
					<ListBoxItem>
						<Border Width="30" Height="30" Background="SteelBlue" Margin="3,1,3,1"/>
					</ListBoxItem>
					<ListBoxItem>
						<Border Width="30" Height="30" Background="Green" Margin="3,1,3,1"/>
					</ListBoxItem>
					<ListBoxItem>
						<Border Width="30" Height="30" Background="DarkGray" Margin="3,1,3,1"/>
					</ListBoxItem>
					<ListBoxItem>
						<Border Width="30" Height="30" Background="Orange" Margin="3,1,3,1"/>
					</ListBoxItem>

				</ListBox>

		</DockPanel>

		<telerik:RadDocking Name="radDocking1" HasDocumentHost="True" Grid.Row="1" telerik:StyleManager.Theme="Windows7">
			<telerik:RadDocking.Resources>
<!--                <Style TargetType="telerik:RadPane">-->
			<!--                    <Setter Property="IsPinned" Value="False"/>-->
			<!--                </Style>-->
			</telerik:RadDocking.Resources>
			<telerik:RadDocking.DocumentHost>
				<telerik:RadSplitContainer >
					<telerik:RadPaneGroup>
						<telerik:RadDocumentPane CanFloat="False" CanUserClose="False"  Header="Source file">
							<WindowsFormsHost Name="sourceCodeContent">
								<wf:RichTextBox  AcceptsTab="True"  Font="Courier New, 12pt, style=Bold"  ForeColor="Black" TextChanged="SourceCodeChanged">

								</wf:RichTextBox>
							</WindowsFormsHost>
						</telerik:RadDocumentPane>
					</telerik:RadPaneGroup>
				</telerik:RadSplitContainer>
			</telerik:RadDocking.DocumentHost>
			<telerik:RadSplitContainer InitialPosition="DockedBottom" Orientation="Horizontal">
				<telerik:RadPaneGroup >
					<telerik:RadPane CanUserClose="False" Header="Errors"  Name="errorsPane" IsPinned="True">
						<telerik:RadPane.HeaderTemplate>
							<DataTemplate>
								<StackPanel VerticalAlignment="Center" Orientation="Horizontal" Margin="2,2,5,2">
									<Image Source="../Resources/Errors.png" Height="15" Width="15" Stretch="Fill" />
									<TextBlock VerticalAlignment="Center" Text="Errors"/>

								</StackPanel>
							</DataTemplate>

						</telerik:RadPane.HeaderTemplate>
						<telerik:RadGridView AutoGenerateColumns="False"   VerticalAlignment="Stretch" ShowGroupPanel="False" HorizontalAlignment="Stretch" ItemsSource="{Binding ElementName=LocalThis, Path=ViewModel.Errors}"  CanUserSelect="False">

							<telerik:RadGridView.Columns>
								<telerik:GridViewDataColumn Width="Auto" Header="Line" DataMemberBinding="{Binding Path=Item1}"/>
								<telerik:GridViewDataColumn Width="*" Header="Error" DataMemberBinding="{Binding Path=Item2}"/>
							</telerik:RadGridView.Columns>
						</telerik:RadGridView>
					</telerik:RadPane>
					<telerik:RadPane CanUserClose="False" Header="Execution History" Name="historyPane" IsPinned="True" >
						<telerik:RadGridView ShowGroupPanel="False" AutoGenerateColumns="False" telerik:StyleManager.Theme="Summer" RowDetailsVisibilityMode="VisibleWhenSelected"  SelectionMode="Single" ItemsSource="{Binding ElementName=LocalThis, Path=ViewModel.CurrentEmulator.InstructionHistory}">

							<telerik:RadGridView.RowDetailsTemplate>
								<DataTemplate>
                                    <telerik:RadGridView AutoGenerateColumns="False" telerik:StyleManager.Theme="Summer"  VerticalAlignment="Stretch" HorizontalAlignment="Left" IsReadOnly="True" ShowGroupPanel="False" ItemsSource="{Binding Path=TsHistory}" MaxWidth="1000" >
                                        
                                        <telerik:RadGridView.Columns>
											<telerik:GridViewDataColumn IsReadOnly="True" Width="Auto" Header="Ts" Background="Green"  DataMemberBinding="{Binding Path=TName}"/>
											<telerik:GridViewDataColumn IsReadOnly="True" Width="*" Header="PC"  DataMemberBinding="{Binding Path=ComputerRegisters, Converter={StaticResource _cpuContentToString}, ConverterParameter=PC}"/>
											<telerik:GridViewDataColumn IsReadOnly="True" Width="*" Header="AR"  DataMemberBinding="{Binding Path=ComputerRegisters, Converter={StaticResource _cpuContentToString}, ConverterParameter=AR}"/>
											<telerik:GridViewDataColumn IsReadOnly="True" Width="*" Header="AC"  DataMemberBinding="{Binding Path=ComputerRegisters, Converter={StaticResource _cpuContentToString}, ConverterParameter=AC}"/>
											<telerik:GridViewDataColumn IsReadOnly="True" Width="*" Header="IR"  DataMemberBinding="{Binding Path=ComputerRegisters, Converter={StaticResource _cpuContentToString}, ConverterParameter=IR}"/>
											<telerik:GridViewDataColumn IsReadOnly="True" Width="*" Header="TR"  DataMemberBinding="{Binding Path=ComputerRegisters, Converter={StaticResource _cpuContentToString}, ConverterParameter=TR}"/>
											<telerik:GridViewDataColumn IsReadOnly="True" Width="*" Header="DR"  DataMemberBinding="{Binding Path=ComputerRegisters, Converter={StaticResource _cpuContentToString}, ConverterParameter=DR}"/>
											<telerik:GridViewDataColumn IsReadOnly="True" Width="*" Header="INPR" DataMemberBinding="{Binding Path=ComputerRegisters, Converter={StaticResource _cpuContentToString}, ConverterParameter=INPR}"/>
											<telerik:GridViewDataColumn IsReadOnly="True" Width="*" Header="OUTR" DataMemberBinding="{Binding Path=ComputerRegisters, Converter={StaticResource _cpuContentToString}, ConverterParameter=OUTR}"/>

											<telerik:GridViewDataColumn IsReadOnly="True" Width="*" Header="E" DataMemberBinding="{Binding Path=ComputerFlags, Converter={StaticResource _cpuContentToString}, ConverterParameter=E}"/>
											<telerik:GridViewDataColumn IsReadOnly="True" Width="*" Header="I" DataMemberBinding="{Binding Path=ComputerFlags, Converter={StaticResource _cpuContentToString}, ConverterParameter=I}"/>
											<telerik:GridViewDataColumn IsReadOnly="True" Width="*" Header="S" DataMemberBinding="{Binding Path=ComputerFlags, Converter={StaticResource _cpuContentToString}, ConverterParameter=S}"/>
											<telerik:GridViewDataColumn IsReadOnly="True" Width="*" Header="R" DataMemberBinding="{Binding Path=ComputerFlags, Converter={StaticResource _cpuContentToString}, ConverterParameter=R}"/>
											<telerik:GridViewDataColumn IsReadOnly="True" Width="*" Header="FGI" DataMemberBinding="{Binding Path=ComputerFlags, Converter={StaticResource _cpuContentToString}, ConverterParameter=FGI}"/>
											<telerik:GridViewDataColumn IsReadOnly="True" Width="*" Header="FGO" DataMemberBinding="{Binding Path=ComputerFlags, Converter={StaticResource _cpuContentToString}, ConverterParameter=FGO}"/>
											<telerik:GridViewDataColumn IsReadOnly="True"  Width="Auto" Header="IEN" DataMemberBinding="{Binding Path=ComputerFlags, Converter={StaticResource _cpuContentToString}, ConverterParameter=IEN}"/>
										</telerik:RadGridView.Columns>
									</telerik:RadGridView>
								</DataTemplate>
							</telerik:RadGridView.RowDetailsTemplate>
							<telerik:RadGridView.Columns>
                                <telerik:GridViewDataColumn IsReadOnly="True" telerik:StyleManager.Theme="Summer" Width="3*" Header="Instrruction machine code" DataMemberBinding="{Binding Path=InstructionMachineCode}"/>

								<telerik:GridViewDataColumn IsReadOnly="True" Width="*" Header="PC"  DataMemberBinding="{Binding Path=LastCpu.ComputerRegisters, Converter={StaticResource _cpuContentToString}, ConverterParameter=PC}"/>
								<telerik:GridViewDataColumn IsReadOnly="True" Width="*" Header="AR"  DataMemberBinding="{Binding Path=LastCpu.ComputerRegisters, Converter={StaticResource _cpuContentToString}, ConverterParameter=AR}"/>
								<telerik:GridViewDataColumn IsReadOnly="True" Width="*" Header="AC"  DataMemberBinding="{Binding Path=LastCpu.ComputerRegisters, Converter={StaticResource _cpuContentToString}, ConverterParameter=AC}"/>
								<telerik:GridViewDataColumn IsReadOnly="True" Width="*" Header="IR"  DataMemberBinding="{Binding Path=LastCpu.ComputerRegisters, Converter={StaticResource _cpuContentToString}, ConverterParameter=IR}"/>
								<telerik:GridViewDataColumn IsReadOnly="True" Width="*" Header="TR"  DataMemberBinding="{Binding Path=LastCpu.ComputerRegisters, Converter={StaticResource _cpuContentToString}, ConverterParameter=TR}"/>
								<telerik:GridViewDataColumn IsReadOnly="True" Width="*" Header="DR"  DataMemberBinding="{Binding Path=LastCpu.ComputerRegisters, Converter={StaticResource _cpuContentToString}, ConverterParameter=DR}"/>
								<telerik:GridViewDataColumn IsReadOnly="True" Width="*" Header="INPR" DataMemberBinding="{Binding Path=LastCpu.ComputerRegisters, Converter={StaticResource _cpuContentToString}, ConverterParameter=INPR}"/>
								<telerik:GridViewDataColumn IsReadOnly="True" Width="*" Header="OUTR" DataMemberBinding="{Binding Path=LastCpu.ComputerRegisters, Converter={StaticResource _cpuContentToString}, ConverterParameter=OUTR}"/>

								<telerik:GridViewDataColumn IsReadOnly="True" Width="*" Header="E" DataMemberBinding="{Binding Path=LastCpu.ComputerFlags, Converter={StaticResource _cpuContentToString}, ConverterParameter=E}"/>
								<telerik:GridViewDataColumn IsReadOnly="True" Width="*" Header="I" DataMemberBinding="{Binding Path=LastCpu.ComputerFlags, Converter={StaticResource _cpuContentToString}, ConverterParameter=I}"/>
								<telerik:GridViewDataColumn IsReadOnly="True" Width="*" Header="S" DataMemberBinding="{Binding Path=LastCpu.ComputerFlags, Converter={StaticResource _cpuContentToString}, ConverterParameter=S}"/>
								<telerik:GridViewDataColumn IsReadOnly="True" Width="*" Header="R" DataMemberBinding="{Binding Path=LastCpu.ComputerFlags, Converter={StaticResource _cpuContentToString}, ConverterParameter=R}"/>
								<telerik:GridViewDataColumn IsReadOnly="True" Width="*" Header="FGI" DataMemberBinding="{Binding Path=LastCpu.ComputerFlags, Converter={StaticResource _cpuContentToString}, ConverterParameter=FGI}"/>
								<telerik:GridViewDataColumn IsReadOnly="True" Width="*" Header="FGO" DataMemberBinding="{Binding Path=LastCpu.ComputerFlags, Converter={StaticResource _cpuContentToString}, ConverterParameter=FGO}"/>
								<telerik:GridViewDataColumn IsReadOnly="True" Width="Auto" Header="IEN" DataMemberBinding="{Binding Path=LastCpu.ComputerFlags, Converter={StaticResource _cpuContentToString}, ConverterParameter=IEN}"/>

							</telerik:RadGridView.Columns>
						</telerik:RadGridView>
					</telerik:RadPane>
					<!--                    <telerik:RadPane CanUserClose="False" Header="Assembler - Pass 1" Name="asmPass1Pane" IsPinned="False"/>-->
					<!--                    <telerik:RadPane CanUserClose="False" Header="Assembler - Pass 2" Name="asmPass2Pane" IsPinned="False"/>-->
				</telerik:RadPaneGroup>
			</telerik:RadSplitContainer>
			<telerik:RadSplitContainer InitialPosition="DockedRight" Orientation="Horizontal" >
				<telerik:RadPaneGroup>
					<telerik:RadPane CanUserClose="False" Header="Memory Map" Name="memoryPane" IsPinned="False">
						<telerik:RadGridView EnableRowVirtualization="True"  x:Name="memoryMapGrid"  ScrollMode="Deferred"  AutoGenerateColumns="False" VerticalAlignment="Stretch" ShowGroupPanel="False" HorizontalAlignment="Stretch"
											 ItemsSource="{Binding ElementName=LocalThis, Path=ViewModel.CurrentEmulator.Memory}"  CanUserSelect="False">
                            <telerik:RadGridView.ScrollPositionIndicatorTemplate>
                                <DataTemplate>
                                    <ContentPresenter Margin="40,5,40,6" Content="{Binding}">
                                        <ContentPresenter.ContentTemplate>
                                            <DataTemplate>
                                                <Grid IsHitTestVisible="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                                                    <Grid.RowDefinitions>
                                                        <RowDefinition Height="Auto" />
                                                        <RowDefinition Height="Auto" />
                                                    </Grid.RowDefinitions>
                                                    <StackPanel Grid.Row="0" VerticalAlignment="Center" Orientation="Horizontal" >
                                                        <TextBlock Text="Location: " FontWeight="Bold"/>
                                                        <TextBlock Text="{Binding Address, StringFormat='\{0:X}'}" />
                                                    </StackPanel>
                                                    <StackPanel Grid.Row="1" VerticalAlignment="Center" Orientation="Horizontal" >
                                                        <TextBlock Text="Value: " FontWeight="Bold"/>
                                                        <TextBlock Text="{Binding Value}" />
                                                    </StackPanel>
                                                </Grid>
                                            </DataTemplate>
                                        </ContentPresenter.ContentTemplate>
                                    </ContentPresenter>
                                </DataTemplate>
                            </telerik:RadGridView.ScrollPositionIndicatorTemplate>
                            <telerik:RadGridView.Columns>
								<telerik:GridViewDataColumn Width="Auto" Header="Location" DataMemberBinding="{Binding Path=Address, StringFormat='\{0:X}'}"/>
								<telerik:GridViewDataColumn Width="*" Header="Hex" DataMemberBinding="{Binding Path=Value, StringFormat='\{0:X}'}"/>
								<telerik:GridViewDataColumn Width="*" Header="Dec" DataMemberBinding="{Binding Path=Value}"/>
							</telerik:RadGridView.Columns>
						</telerik:RadGridView>
					</telerik:RadPane>
					<telerik:RadPane CanUserClose="False" Header="Symbols Table" Name="asmSymbolsPane" IsPinned="False">
						<telerik:RadGridView AutoGenerateColumns="False" VerticalAlignment="Stretch" ShowGroupPanel="False" HorizontalAlignment="Stretch"
											 ItemsSource="{Binding ElementName=LocalThis, Path=ViewModel.SymbolsTable}"  CanUserSelect="False">

							<telerik:RadGridView.Columns>
								<telerik:GridViewDataColumn Width="Auto" Header="Symbol" DataMemberBinding="{Binding Path=Item1}"/>
								<telerik:GridViewDataColumn Width="*" Header="Address" DataMemberBinding="{Binding Path=Item2}"/>
							</telerik:RadGridView.Columns>
						</telerik:RadGridView>
					</telerik:RadPane>
				</telerik:RadPaneGroup>
			</telerik:RadSplitContainer>
			</telerik:RadDocking>

			<StatusBar Grid.Row="2" HorizontalAlignment="Stretch" Height="20" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
				<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">

					<TextBlock Text="{Binding ElementName=LocalThis, Path=ViewModel.CurrentEmulator.CurrentInstructionString, FallbackValue='No instructions'}" VerticalAlignment="Center" Grid.Column="1" HorizontalAlignment="Right" />
				</Grid>
			</StatusBar>
	</Grid>
</Window>